package com.mastercard.auth

import com.mastercard.CreditCard
import com.mastercard.Category
import com.mastercard.Budget

class User {
	static auditable = true
	
	enum Status {LIVE,LOCKED,SUSPEND,DELETED,PENDING_EMAIL_ACTIVICATION,PENDING_PHONE_ACTIVATION}
	String login
    String email
    String password
	String name
	String mobile
	String homePhone
	String gender
	Date birthDate
	Date dateCreated
	Status status
	List creditCards
	List categories
	List addresses
	List userActivations
	
    static hasMany = [roles:Role, permissions:String, addresses:Address, creditCards: CreditCard, categories: Category, userActivations:UserActivation]
    static constraints = {
        email email: true, unique: true, blank: false
        login blank: false, size: 5..15
        password blank: false, nullable: false
		status blank:false, nullable:false
		name nullable: true
		gender nullable :true
		birthDate nullable :true
		mobile nullable: true
		homePhone nullable: true
		addresses nullable: true
		userActivations nullable:true
    }

    static mapping = {
        cache true
		addresses cascade: 'all-delete-orphan'
    }

    String toString() {
        email
    }
	
	def beforeInsert() {
		Date dt = new Date()
		dateCreated = dt
	}
}